import { defineStore } from 'pinia'
import { darkTheme, lightTheme } from 'naive-ui'
import type { BuiltInGlobalTheme } from 'naive-ui/es/themes/interface'

export const useAppStore = defineStore('app', {
  state: () => {
    return {
      theme: 'light'
    }
  },
  persist: [
    {
      paths: ['theme'],
      storage: localStorage
    }
  ],
  actions: {
    changeTheme(theme: string) {
      this.theme = theme
    }
  },
  getters: {
    currentTheme(): BuiltInGlobalTheme {
      return this.theme === 'light' ? lightTheme : darkTheme
    }
  }
})
